<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-nested" prefix="nested" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ page contentType="text/html; charset=utf-8"  import="com.leexuan.ordersystem.beans.*" import="com.leexuan.ordersystem.*"  import="com.leexuan.ordersystem.db.*"  import="java.util.*"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">

<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<LINK href="css/admincp.css" type=text/css rel=stylesheet>
<html:base/>

<script language="javascript">

rows = 1;

function addRow()
{
	var newTr = document.all.plist.insertRow();
	rows++;
	
	var newTd0 = newTr.insertCell();
	var newTd1 = newTr.insertCell();
	var newTd2 = newTr.insertCell();
	var newTd3 = newTr.insertCell();
	var newTd4 = newTr.insertCell();
	var newTd5 = newTr.insertCell();
	var newTd6 = newTr.insertCell();
	var newTd7 = newTr.insertCell();	

	newTd0.innerHTML = '<TD class=altbg1></TD>';
	newTd1.innerHTML = '<TD class=altbg2></TD>';
	newTd2.innerHTML = '<TD class=altbg1></TD>';
	newTd3.innerHTML = '<TD class=altbg2></TD>';
	newTd4.innerHTML = '<TD class=altbg1></TD>';
	newTd5.innerHTML = '<TD class=altbg2></TD>';
	newTd6.innerHTML = '<TD class=altbg2></TD>';		
	newTd7.innerHTML = '<TD class=altbg1><a href=chooseProduct.do>选择产品</a></TD>';	
	

}
     
function deleteRow()
{
	if(rows>0)
	{
		document.all("plist").deleteRow(rows);
		rows--;
	}
}
</script>

<SCRIPT language=JavaScript>
function check(){

	if(document.getElementsByName("name")[0].value==""){
		alert("客户名称不能为空！");
		return false;
	}
	if(document.getElementsByName("address")[0].value==""){
		alert("客户地址不能为空！");
		return false;
	}
	if(document.getElementsByName("account")[0].value==""){
		alert("银行账号不能为空！");
		return false;
	}	
	if(document.getElementsByName("bank")[0].value==""){
		alert("开户银行不能为空！");
		return false;
	}
	
	var re=/^\d{4}-\d{1,2}-\d{1,2}$/;
	var str=document.getElementsByName("date")[0].value;
	var r=str.match(re);
	if (r==null){
		alert('请输入正确的定购日期，如：2006-01-01');
		document.getElementsByName("date")[0].focus();
		return false;
	}

	var str=document.getElementsByName("ddate")[0].value;
	var r=str.match(re);
	if (r==null){
		alert('请输入正确的发货日期，如：2006-01-01');
		document.getElementsByName("ddate")[0].focus();
		return false;
	}	

	if(document.getElementsByName("choosep")[0].value=="no"){
		alert("请选择所定购的产品！");
		return false;
	}	
	



	
	return true;
	
}
</SCRIPT>

</HEAD>
<BODY topMargin=10>
<TABLE cellSpacing=6 cellPadding=2 width="100%" border=0>
  <TBODY>
  <TR>
    <TD>
      <TABLE class=guide cellSpacing=0 cellPadding=0 width="100%" border=0>
        <TBODY>
        <TR>
          <TD>订单管理&nbsp;>>&nbsp;增加订单</TD></TR></TBODY></TABLE><BR>
      <TABLE class=tableborder cellSpacing=0 cellPadding=0 width="100%" border=0>
        <TBODY>
        <TR class=header>
          <TD colSpan=3>客户信息</TD></TR>
          
<%
float sum = 0;
ArrayList arraylist = (ArrayList)session.getAttribute("orderDetail");
if(arraylist != null){
	Product[] pts  = new Product[arraylist.size()];
	arraylist.toArray(pts);
	for(int i=0;i<pts.length;i++){
		sum += pts[i].getPrice()*pts[i].getNum();
	}
}

Customer cs = (Customer)session.getAttribute("orderCustomer");

%>          

	<html:form action="/addCustomer.do" method="post">
        <TR>
          <TD class=altbg1 width="20%">客户名称：</TD>
          <TD class=altbg2 align=right width="50%">
          <input type=text size=25 name="name" value=<%=cs==null?"":cs.getName()+" readonly"  %>>
          </TD>
          <td width="30%" align=left>
          <%if(cs == null){ %>
          <a href="chooseCustomer.do">选择已有客户</a>
          <%}else{ %>
          <a href="chooseCustomerAgain.do">重新输入客户</a>
          <%} %>      
          
          </td>
          </TR>

        <TR>
          <TD class=altbg1>客户开户银行：</TD>
          <TD class=altbg2 align=right>
          <input type=text size=25  name="bank" value=<%=cs==null?"":cs.getBank()+" readonly"  %>></TD>
          <td></td></TR>
        <TR>
          <TD class=altbg1>客户银行帐号：</TD>
          <TD class=altbg2 align=right>
          <input type=text size=35  name="account" value=<%=cs==null?"":cs.getAccount()+" readonly"  %>></TD>
          <td></td></TR>
        <TR>
          <TD class=altbg1>客户地址：</TD>
          <TD class=altbg2 align=right>
          <input type=text size=50  name="address" value=<%=cs==null?"":cs.getAddress()+" readonly" %>></TD>  
          <td>
          <%if(cs == null){ %>
          <input type="submit" value="增加新客户" onclick="return check();">
          <%}else{%>
          <span style="color:#FF0000">客户资料已经输入</span>
          <%} %>
          
          <input type="hidden" name="ordercustomer" value="1">
          </td>   </TR>   
          
          </html:form>                                               
      </TBODY></TABLE><BR>
      <html:form action="/addOrder.do" method="post">
 
      <TABLE class=tableborder cellSpacing=0 cellPadding=0 width="100%" 
border=0>
        <TBODY>
        <TR class=header>
          <TD colSpan=2>订单信息</TD></TR>
<%

DsortDB db = new DsortDB();
db.getConnection();

ArrayList arraylist2 =new ArrayList();
arraylist2 = db.getDsorts();

Dsort[] dsorts  = new Dsort[arraylist2.size()];
arraylist2.toArray(dsorts);
db.closeConnection();
%>
        <TR>
          <TD class=altbg1>定购日期：</TD>
          <TD class=altbg2 align=right><input id="od" name="date" type=text size=20></TD></TR>
        <TR>
          <TD class=altbg1>发货日期：</TD>
          <TD class=altbg2 align=right><input id="dd" name="ddate"type=text size=20></TD></TR>
        <TR>
          <TD class=altbg1>发货方式：</TD>
          <TD class=altbg2 align=right>
          <select name="dtype">
          <%for(int i =0;i<dsorts.length;i++){ %>
          <option value="<%=dsorts[i].getDsid() %>"><%=dsorts[i].getName() %></option>
          <%} %>
		  </TD></TR>              
        <TR>
          <TD class=altbg1>订单总金额：</TD>
          <TD class=altbg2 align=right><%= sum %> 元</TD></TR>
          <input type=hidden name=sum value=<%= sum %> >
        <TR>
          <TD class=altbg1>经办人：</TD>
          
<%
Admin admin = null;
admin = (Admin)session.getAttribute("admin");
%>          
          <TD class=altbg2 align=right><%=admin.getName() %></TD></TR>                                                                
      </TBODY></TABLE><BR>
 
<TABLE class=tableborder cellSpacing=0 cellPadding=0 width="100%" 
border=0 id="plist">
        <TBODY>
        
        <TR class=header>
          <TD width="15%">产品编号</TD>
          <TD width="15%">产品名称</TD>
          <TD width="20%">产品型号</TD>
          <TD width="10%">分类</TD>
          <TD width="10%">售价</TD>
          <TD width="10%">定购数量</TD>
          <TD width="10%">单项小计</TD>       
          <TD>操作</TD></TR>        
<%


if((arraylist!=null)&& (arraylist.size()>0)){
	Product[] pts  = new Product[arraylist.size()];
	arraylist.toArray(pts);
	for(int i=0;i<pts.length;i++){
%>		
        <TR align=middle>
          <TD class=altbg1><%=pts[i].getNumber()%></TD>
          <TD class=altbg2><%=pts[i].getName() %></TD>
          <TD class=altbg1><%=pts[i].getModel() %></TD>
          <TD class=altbg2><%=pts[i].getSname() %></TD>
          <TD class=altbg1><%=pts[i].getPrice() %> 元</TD>
          <TD class=altbg2><%=pts[i].getNum() %></TD>
          <TD class=altbg1><%=pts[i].getNum()*pts[i].getPrice() %> 元</TD>
          <TD><a href="delOrderProduct.do?index=<%=i%>">去掉产品</a></TD>
          </TR>
<%
	}
}else{

%>         
       
        <TR align=middle>
          <TD class=altbg1></TD>
          <TD class=altbg2></TD>
          <TD class=altbg1></TD>
          <TD class=altbg2></TD>
          <TD class=altbg1></TD>
          <TD class=altbg2></TD>
          <TD class=altbg1></TD>
          <TD class=altbg2>
          <a href="chooseProduct.do">选择产品</a>
          <input type=hidden name="choosep" value="no">
          </TD>
          </TR>
<%

	}

%>         

</TBODY></TABLE>    

<script type="text/javascript">

var myDate = new Date(); 

document.getElementById("od").value = myDate.getFullYear()+"-"+(myDate.getMonth()+1)+"-"+myDate.getDate();
document.getElementById("dd").value = myDate.getFullYear()+"-"+(myDate.getMonth()+1)+"-"+myDate.getDate();
</script>     
      
      <CENTER>
      <br>
      <INPUT class=button type=button value="增加产品" onclick="addRow();">  

      <INPUT class=button type=submit value="提交订单"  onclick="return check();">
      </CENTER></html:form>
      	</TD></TR></TBODY></TABLE>

<%@include file= "./footer.jsp"%>
